package com.hrh.selectsystem.controller;

import com.hrh.selectsystem.aop.MyJwtInterceptor;
import com.hrh.selectsystem.common.BaseResponse;
import com.hrh.selectsystem.common.ResultUtils;
import com.hrh.selectsystem.service.RoundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "根接口")
@Slf4j
public class RootController {

    @Resource
    private RoundService roundService;

    /**
     * 根据token获取当前用户role
     * @param request
     * @return
     */
    @GetMapping("/get-role")
    @ApiOperation(value = "根据token获取当前用户role")
    public BaseResponse<String> getUserRole(HttpServletRequest request) {
        String userRole = MyJwtInterceptor.getUserRoleFromToken(request.getHeader("token"));
        return ResultUtils.success(userRole);
    }

    /**
     * 获取当前轮次
     * @return
     */
    @GetMapping("/get-round")
    @ApiOperation(value = "获取当前轮次")
    public BaseResponse<Integer> getRound() {
        return ResultUtils.success(roundService.getStartedRound());
    }
}
